home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / DLGUSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  19.4 KB  |  748 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // DialogClass
  8. //
  9.  
  10. #include "fli.h"
  11.  
  12. #ifdef __BCPLUSPLUS__
  13. #pragma hdrstop
  14. #endif
  15.  
  16. #include <bios.h>
  17.  
  18. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  19. //
  20. // UseDialog()
  21. //
  22. // Use the dialog
  23. //
  24. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25.  
  26. int DialogClass::UseDialog()
  27. {
  28. RestartHere:
  29.  
  30.   int KeyPress;
  31.   DialogElement *Locator, *Magnet=0, *StoreMagnet;
  32.  
  33.   int ReturnElement;
  34.  
  35.   if (!(+Blaze))
  36.     +Blaze;
  37.  
  38.   if (!First)
  39.     return NoElement;
  40.  
  41.   if (!MultiTask || (MultiTask && !LocatedFirst))
  42.   {
  43.     Blaze.BigCursor();
  44.  
  45.     Present=First;
  46.  
  47.     do
  48.     {
  49.       if (Present->Available()==CompleteEvent)
  50.         break;
  51.       Present=Present->Next;
  52.     }
  53.     while (Present);
  54.  
  55.     if (!Present)
  56.       return NoAvailableElement;
  57.   }
  58.  
  59.   if (!BottomSave)
  60.   {
  61.     MouseHide();
  62.     BottomSave=new char[Blaze.ComputeNeededBytes(Blaze.WhatWidth(),1)];
  63.     Blaze.GetArea(0,Blaze.WhatHeight()-1,Blaze.WhatWidth(),1,BottomSave);
  64.     MouseShow();
  65.   }
  66.  
  67.   if (!MultiTask || (MultiTask && !LocatedFirst))
  68.   {
  69.     LocatedFirst=1;
  70.     LastPresent=0;
  71.     ShowElements();
  72.     ShowHeading(0);
  73.     FlushMouseQueue();
  74.     Blaze.BigCursor();
  75.   }
  76.  
  77.   for (;;)
  78.   {
  79.  
  80. NewEvent:
  81.  
  82.     if (!Arrive(*Present))
  83.       goto ExitGracefully;
  84.  
  85.     Blaze.VisibleCursor();
  86.  
  87.     HelpId=Present->FusionHelp;
  88.  
  89.     if (MultiTask || UseAction)
  90.     {
  91.       while(!(KeyPress=GetEvent(1)))
  92.       {
  93.         if (UseAction && biostime(0,0)>(ActionTimer+DialogTimer))
  94.         {
  95.           if (CallAllActions()==RefreshEvent)
  96.             goto Refresh;
  97.           ActionTimer=biostime(0,0);
  98.         }
  99.  
  100.         if (MultiTask)
  101.           return 0;
  102.       }
  103.     }
  104.     else
  105.       KeyPress=GetEvent();
  106.  
  107.     switch (KeyPress)
  108.     {
  109.       case MoveEvent:
  110.         Blaze.Window(X+1,Y+1,Width-2,Height-2);
  111.         Present->HighLight();
  112.         Blaze.VisibleCursor();
  113.         ShowLocator();
  114.         Blaze.GetXY(XSave,YSave);
  115.         continue;
  116.  
  117.       case HelpEvent:
  118.         Blaze.GotoXY(XSave,YSave);
  119.         Blaze.VisibleCursor();
  120.         ShowLocator(1);
  121.         continue;
  122.  
  123.       default:
  124.  
  125.         if (!NoDefaults)
  126.         {
  127.           if (KeyPress==kbTab)
  128.           {
  129. JumpNext:
  130.  
  131.             Magnet=0;
  132.  
  133.             if (!Valid())
  134.               continue;
  135.  
  136.             if (!NextGroup())
  137.               goto ExitGracefully;
  138.  
  139.             continue;
  140.           }
  141.           if (KeyPress==kbShiftTab)
  142.           {
  143. JumpLast:
  144.  
  145.             Magnet=0;
  146.  
  147.             if (!Valid())
  148.               continue;
  149.  
  150.             if (!PreviousGroup())
  151.               goto ExitGracefully;
  152.  
  153.             continue;
  154.           }
  155.         }
  156.  
  157.         Locator=First;
  158.  
  159.         if (KeyPress==MousedEvent)
  160.         {
  161.           if ((MouseEvent&MouseLeftButtonRelease ||
  162.                MouseEvent&MouseLeftButtonPress)
  163.  
  164.                && MouseHorizontal>X
  165.                && MouseHorizontal<X+Width-1
  166.                && MouseVertical>Y
  167.                && MouseVertical<Y+Height-1)
  168.           {
  169.             int ActualX;
  170.             int ActualY;
  171.  
  172.             if (Y)
  173.             {
  174.               ActualX=MouseHorizontal-(X+1);
  175.               ActualY=MouseVertical-(Y+1);
  176.             }
  177.             else
  178.             {
  179.               ActualX=MouseHorizontal-X;
  180.               ActualY=MouseVertical-Y;
  181.             }
  182.  
  183.             // --------------------------------------------------------------
  184.             // Since a mouse button was released, see if the mouse is
  185.             // currently touching an element.  If so, move to it if it is
  186.             // available for access.
  187.             // --------------------------------------------------------------
  188.  
  189.             StoreMagnet=Present;
  190.  
  191.             do
  192.             {
  193.               if (ActualX>=Locator->X
  194.                 && ActualX<Locator->X+Locator->Width
  195.                 && ActualY>=Locator->Y
  196.                 && ActualY<Locator->Y+Locator->Height
  197.                 && Locator->Available()!=FailedEvent
  198.                 && Locator!=Present)
  199.               {
  200.                 if (!Valid())
  201.                   goto NewEvent;
  202.  
  203.                 MouseHide();
  204.  
  205.                 if (!Depart(*Present))
  206.                   goto ExitGracefully;
  207.  
  208.                 Present=Locator;
  209.  
  210.                 if (!Arrive(*Present))
  211.                   goto ExitGracefully;
  212.  
  213.                 MouseHorizontal=ActualX;
  214.                 MouseVertical=ActualY;
  215.                 MouseShow();
  216.  
  217.                 KeyPress=ValidatedMousedEvent;
  218.                 Magnet=StoreMagnet;
  219.  
  220.                 goto ProcessEvent;
  221.               }
  222.               Locator=Locator->Next;
  223.             }
  224.             while (Locator);
  225.  
  226.             goto PassMouseEventFurther;
  227.           }
  228.           else
  229.           {
  230.  
  231. PassMouseEventFurther:
  232.  
  233.             if (Y)
  234.             {
  235.               MouseHorizontal-=(X+1);
  236.               MouseVertical-=(Y+1);
  237.             }
  238.             else
  239.             {
  240.               MouseHorizontal-=X;
  241.               MouseVertical-=Y;
  242.             }
  243.  
  244.  
  245.             if (MouseHorizontal>=Present->X
  246.               && MouseHorizontal<Present->X+Present->Width
  247.               && MouseVertical>=Present->Y
  248.               && MouseVertical<Present->Y+Present->Height)
  249.                 KeyPress=ValidatedMousedEvent;
  250.  
  251.             goto ProcessEvent;
  252.           }
  253.         }
  254.  
  255.         // --------------------------------------------------------------
  256.         // Scan through available groups and search for a particular
  257.         // "Hot" key pattern.  Once found, jump to it.  If the key is not
  258.         // a "Hot" key for one of the groups -- pass the key along to
  259.         // the event handler stream (element event -> dialog event)
  260.         // --------------------------------------------------------------
  261.  
  262.         if (HeadingCount)
  263.         {
  264.           for (int i=0;i<HeadingCount;i++)
  265.             if ((HeadingStorage+i)->HotKey==KeyPress &&
  266.               Present->GroupCode!=(HeadingStorage+i)->GroupCode)
  267.             {
  268.               int j=(HeadingStorage+i)->GroupCode;
  269.  
  270.               DialogElement *Pres=Present;
  271.               DialogElement *Present=First;
  272.  
  273.               do
  274.               {
  275.                 if (Present->GroupCode==j &&
  276.                   Present->Available()==CompleteEvent)
  277.                 {
  278.                   if (!Valid())
  279.                     goto NewEvent;
  280.  
  281.                   if (!Depart(*Pres))
  282.                     goto ExitGracefully;
  283.  
  284.                   DialogClass::Present=Present;
  285.  
  286.                   if (!Arrive(*Present))
  287.                     goto ExitGracefully;
  288.  
  289.                   goto NewEvent;
  290.                 }
  291.                 Present=Present->Next;
  292.                 LastPresent=0;
  293.               }
  294.               while (Present);
  295.             }
  296.         }
  297.  
  298.         // --------------------------------------------------------------
  299.         // Scan through available elements and search for a particular
  300.         // "Hot" key pattern.  Once found, jump to it.  If the key is not
  301.         // a "Hot" key for one of the elements -- pass the key along to
  302.         // the event handler stream (element event -> dialog event)
  303.         // --------------------------------------------------------------
  304.  
  305.         Locator=First;
  306.         StoreMagnet=Present;
  307.  
  308.         do
  309.         {
  310.           if (Locator!=Present
  311.               && (Locator->QuickKey==KeyPress ||
  312.               (KeyPress>='a' && KeyPress<='z' &&
  313.               Locator->QuickKey==(KeyPress-32)))
  314.               && Locator->Available()!=FailedEvent)
  315.           {
  316.             if (!Valid())
  317.               goto NewEvent;
  318.  
  319.             if (!Depart(*Present))
  320.               goto ExitGracefully;
  321.  
  322.             Present=Locator;
  323.  
  324.             if (!Arrive(*Present))
  325.               goto ExitGracefully;
  326.  
  327.             LastPresent=0;
  328.  
  329.             Magnet=StoreMagnet;
  330.  
  331.             goto ProcessEvent;
  332.           }
  333.           Locator=Locator->Next;
  334.         }
  335.         while (Locator);
  336.  
  337.         // --------------------------------------------------------------
  338.         // Pass key or mouse event along to element event handler for
  339.         // processing.  If the element event handler doesn't use it, it
  340.         // will be passed to the dialog (global) event handler for
  341.         // processing and final distribution.
  342.         // --------------------------------------------------------------
  343.  
  344. ProcessEvent:
  345.  
  346.         switch (ReturnElement=Present->EventHandler(KeyPress))
  347.         {
  348.           case StopEvent:
  349.             if (!Valid())
  350.               continue;
  351.           case AbortEvent:
  352.             MouseHide();
  353.             if (BottomSave)
  354.             {
  355.               Blaze.PutArea(0,Blaze.WhatHeight()-1,BottomSave);
  356.               delete BottomSave;
  357.               BottomSave=0;
  358.             }
  359.             MouseShow();
  360.             AlreadyShown=0;
  361.             Blaze.BigCursor();
  362.             return KeyPress;
  363.  
  364.           case FullValidationEvent:
  365.  
  366.             {
  367.               DialogElement *FullCheck=First;
  368.  
  369.               do
  370.               {
  371.                 if (FullCheck->Available()==CompleteEvent &&
  372.                   FullCheck->Validation()==FailedEvent)
  373.                 {
  374.                   if (!Depart(*Present))
  375.                     goto ExitGracefully;
  376.  
  377.                   Present=FullCheck;
  378.  
  379.                   if (!Arrive(*Present))
  380.                     goto ExitGracefully;
  381.  
  382.                   LastPresent=0;
  383.                   Magnet=0;
  384.  
  385.                   EventHandler(FullValidationEvent);
  386.  
  387.                   goto NewEvent;
  388.                 }
  389.                 FullCheck=FullCheck->Next;
  390.               }
  391.               while (FullCheck);
  392.  
  393.               MouseHide();
  394.               if (BottomSave)
  395.               {
  396.                 Blaze.PutArea(0,Blaze.WhatHeight()-1,BottomSave);
  397.                 delete BottomSave;
  398.                 BottomSave=0;
  399.               }
  400.               MouseShow();
  401.               AlreadyShown=0;
  402.               Blaze.BigCursor();
  403.               return KeyPress;
  404.             }
  405.  
  406.           case RestartEvent:
  407.             LastPresent=0;
  408.             goto RestartHere;
  409.  
  410.           case CompleteEvent:
  411.             Magnet=0;
  412.             if (Present->Available()==FailedEvent)
  413.               goto JumpNext;
  414.             continue;
  415.  
  416.           case RefreshEvent:
  417.  
  418. Refresh:
  419.  
  420.             Magnet=0;
  421.             LastPresent=0;
  422.             AlreadyShown=0;
  423.             ShowElements();
  424.             if (Present->Available()==FailedEvent)
  425.               goto JumpNext;
  426.             Present->HighLight();
  427.             continue;
  428.  
  429.           case OtherRefreshEvent:
  430.  
  431. OtherRefresh:
  432.  
  433.             Magnet=0;
  434.             LastPresent=0;
  435.             AlreadyShown=0;
  436.             ShowElements(1);
  437.             if (Present->Available()==FailedEvent)
  438.               goto JumpNext;
  439.             Present->HighLight();
  440.             continue;
  441.  
  442.           case NextElementEvent:
  443.             Magnet=0;
  444.             if (!Valid())
  445.               continue;
  446.             if (!NextElement())
  447.               goto ExitGracefully;
  448.             continue;
  449.  
  450.           case PreviousElementEvent:
  451.             Magnet=0;
  452.             if (!Valid())
  453.               continue;
  454.             if (!PreviousElement())
  455.               goto ExitGracefully;
  456.             continue;
  457.  
  458.           case NextGroupEvent:
  459.             Magnet=0;
  460.             if (!Valid())
  461.               continue;
  462.             if (!NextGroup())
  463.               goto ExitGracefully;
  464.             continue;
  465.  
  466.           case PreviousGroupEvent:
  467.             Magnet=0;
  468.             if (!Valid())
  469.               continue;
  470.             if (!PreviousGroup())
  471.               goto ExitGracefully;
  472.             continue;
  473.  
  474.           case NextWithinGroupEvent:
  475.             Magnet=0;
  476.             if (!Valid())
  477.               continue;
  478.             if (!NextWithinGroup())
  479.               goto ExitGracefully;
  480.             continue;
  481.  
  482.           case PreviousWithinGroupEvent:
  483.             Magnet=0;
  484.             if (!Valid())
  485.               continue;
  486.             if (!PreviousWithinGroup())
  487.               goto ExitGracefully;
  488.             continue;
  489.  
  490.           case RefreshMagnetEvent:
  491.           case OtherRefreshMagnetEvent:
  492.           case MagnetEvent:
  493.             if (Magnet && Magnet->Available()==CompleteEvent && Valid())
  494.             {
  495.               if (!Depart(*Present))
  496.                 goto ExitGracefully;
  497.               Present=Magnet;
  498.               if (!Arrive(*Present))
  499.                 goto ExitGracefully;
  500.               Magnet=0;
  501.             }
  502.             Magnet=0;
  503.             if (ReturnElement==RefreshMagnetEvent)
  504.               goto Refresh;
  505.             if (ReturnElement==OtherRefreshMagnetEvent)
  506.               goto OtherRefresh;
  507.  
  508.             continue;
  509.  
  510.           // --------------------------------------------------------------
  511.           // Check for existance of groupings -- if so, jump to a new
  512.           // element within the current group
  513.           // --------------------------------------------------------------
  514.  
  515.           default:
  516.  
  517.             if (Grouped && Grouped>1 && Present->GroupCode &&
  518.               (KeyPress==kbDown || KeyPress==kbUp) && !NoDefaults)
  519.             {
  520.               if (KeyPress==kbDown)
  521.               {
  522.                 Magnet=0;
  523.  
  524.                 if (!Valid())
  525.                   continue;
  526.  
  527.                 if (!NextWithinGroup())
  528.                   goto ExitGracefully;
  529.  
  530.                 continue;
  531.               }
  532.               else
  533.               {
  534.                 Magnet=0;
  535.  
  536.                 if (!Valid())
  537.                   continue;
  538.  
  539.                 if (!PreviousWithinGroup())
  540.                   goto ExitGracefully;
  541.  
  542.                 continue;
  543.               }
  544.             }
  545.  
  546.             // --------------------------------------------------------------
  547.             // Pass the key or mouse event along to the dialog (global) event
  548.             // handler.  If it isn't used during this pass, the event is
  549.             // thrown out and assumed to be a "dead" (unused) event.
  550.             // --------------------------------------------------------------
  551.  
  552.             Blaze.GetXY(XSave,YSave);
  553.  
  554.             int PullBack;
  555.  
  556.             switch (PullBack=EventHandler(ReturnElement))
  557.             {
  558.               case StopEvent:
  559.                 if (!Valid())
  560.                   continue;
  561.               case AbortEvent:
  562.                 Blaze.InvisibleCursor();
  563.                 MouseHide();
  564.                 if (BottomSave)
  565.                 {
  566.                   Blaze.PutArea(0,Blaze.WhatHeight()-1,BottomSave);
  567.                   delete BottomSave;
  568.                   BottomSave=0;
  569.                 }
  570.                 MouseShow();
  571.                 AlreadyShown=0;
  572.                 Blaze.BigCursor();
  573.                 return ReturnElement;
  574.  
  575.               case FullValidationEvent:
  576.  
  577.                 {
  578.                   DialogElement *FullCheck=First;
  579.  
  580.                   do
  581.                   {
  582.                     if (FullCheck->Available()==CompleteEvent &&
  583.                       FullCheck->Validation()==FailedEvent)
  584.                     {
  585.                       if (!Depart(*Present))
  586.                         goto ExitGracefully;
  587.  
  588.                       Present=FullCheck;
  589.  
  590.                       if (!Arrive(*Present))
  591.                         goto ExitGracefully;
  592.  
  593.                       LastPresent=0;
  594.                       Magnet=0;
  595.  
  596.                       EventHandler(FullValidationEvent);
  597.  
  598.                       goto NewEvent;
  599.                     }
  600.                     FullCheck=FullCheck->Next;
  601.                   }
  602.                   while (FullCheck);
  603.  
  604.                   MouseHide();
  605.                   if (BottomSave)
  606.                   {
  607.                     Blaze.PutArea(0,Blaze.WhatHeight()-1,BottomSave);
  608.                     delete BottomSave;
  609.                     BottomSave=0;
  610.                   }
  611.                   MouseShow();
  612.                   AlreadyShown=0;
  613.                   Blaze.BigCursor();
  614.                   return KeyPress;
  615.                 }
  616.  
  617.               case RefreshEvent:
  618.  
  619. GlobalRefresh:
  620.  
  621.                 Blaze.GotoXY(XSave,YSave);
  622.                 Magnet=0;
  623.                 LastPresent=0;
  624.                 AlreadyShown=0;
  625.                 ShowElements();
  626.                 if (Present->Available()==FailedEvent)
  627.                   goto JumpNext;
  628.                 Present->HighLight();
  629.                 continue;
  630.  
  631.               case OtherRefreshEvent:
  632.  
  633. GlobalOtherRefresh:
  634.  
  635.                 Blaze.GotoXY(XSave,YSave);
  636.                 Magnet=0;
  637.                 LastPresent=0;
  638.                 AlreadyShown=0;
  639.                 ShowElements(1);
  640.                 if (Present->Available()==FailedEvent)
  641.                   goto JumpNext;
  642.                 Present->HighLight();
  643.                 continue;
  644.  
  645.               case RestartEvent:
  646.                 LastPresent=0;
  647.                 goto RestartHere;
  648.  
  649.               case NextElementEvent:
  650.                 Magnet=0;
  651.                 if (!Valid())
  652.                   continue;
  653.                 if (!NextElement())
  654.                   goto ExitGracefully;
  655.                 continue;
  656.  
  657.               case PreviousElementEvent:
  658.                 Magnet=0;
  659.                 if (!Valid())
  660.                   continue;
  661.                 if (!PreviousElement())
  662.                   goto ExitGracefully;
  663.                 continue;
  664.  
  665.               case NextGroupEvent:
  666.                 Magnet=0;
  667.                 if (!Valid())
  668.                   continue;
  669.                 if (!NextGroup())
  670.                   goto ExitGracefully;
  671.                 continue;
  672.  
  673.               case PreviousGroupEvent:
  674.                 Magnet=0;
  675.                 if (!Valid())
  676.                   continue;
  677.                 if (!PreviousGroup())
  678.                   goto ExitGracefully;
  679.                 continue;
  680.  
  681.               case NextWithinGroupEvent:
  682.                 Magnet=0;
  683.                 if (!Valid())
  684.                   continue;
  685.                 if (!NextWithinGroup())
  686.                   goto ExitGracefully;
  687.                 continue;
  688.  
  689.               case PreviousWithinGroupEvent:
  690.                 Magnet=0;
  691.                 if (!Valid())
  692.                   continue;
  693.                 if (!PreviousWithinGroup())
  694.                   goto ExitGracefully;
  695.                 continue;
  696.  
  697.               case RefreshMagnetEvent:
  698.               case OtherRefreshMagnetEvent:
  699.               case MagnetEvent:
  700.                 if (Magnet && Magnet->Available()==CompleteEvent && Valid())
  701.                 {
  702.                   if (!Depart(*Present))
  703.                     goto ExitGracefully;
  704.                   Present=Magnet;
  705.                   if (!Arrive(*Present))
  706.                     goto ExitGracefully;
  707.                   Magnet=0;
  708.                 }
  709.                 Magnet=0;
  710.                 if (PullBack==RefreshMagnetEvent)
  711.                   goto GlobalRefresh;
  712.                 if (PullBack==OtherRefreshMagnetEvent)
  713.                   goto GlobalOtherRefresh;
  714.  
  715.                 continue;
  716.  
  717.               case CompleteEvent:
  718.               default:
  719.                 Blaze.GotoXY(XSave,YSave);
  720.                 Blaze.VisibleCursor();
  721.                 if (Present->Available()==FailedEvent)
  722.                   goto JumpNext;
  723.                 continue;
  724.             }
  725.         }
  726.     }
  727.   }
  728.  
  729. ExitGracefully:
  730.  
  731.   MouseHide();
  732.  
  733.   if (BottomSave)
  734.   {
  735.     Blaze.PutArea(0,Blaze.WhatHeight()-1,BottomSave);
  736.     delete BottomSave;
  737.     BottomSave=0;
  738.   }
  739.  
  740.   MouseShow();
  741.  
  742.   Blaze.InvisibleCursor();
  743.   Blaze.BigCursor();
  744.  
  745.   return StopEvent;
  746.  
  747. }
  748.